package com.xdxc.model.bo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.xdxc.emuns.QuestionType;
import com.xdxc.utils.JsonTypeHandler;
import com.xdxc.utils.LongListToStringSerializer;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.List;

@Data
public class UserAnswerWithGrading  implements Serializable {
        // UserAnswer字段
        @JsonSerialize(using = ToStringSerializer.class)

        private Long id;
        @JsonSerialize(using = ToStringSerializer.class)

        private Long paperId;
        @JsonSerialize(using = ToStringSerializer.class)

        private Long quId;
        private QuestionType answerType;
        @TableField(typeHandler = JsonTypeHandler.class)
        private List<Long> answerIds;
        private String answerText;
        private LocalDateTime createTime;

        // 评分结果包装
        private GradingResultWrapper gradingResult;

        // 业务状态字段
        public String getGradingStatus() {
            return gradingResult != null ? "已评分" : "暂未评分";
        }

        @Data
        @NoArgsConstructor
        public static class GradingResultWrapper {
            @JsonSerialize(using = ToStringSerializer.class)

            private Long id;
            private Boolean isCorrect;
            private BigDecimal userScore;
            private String details;
            private String ruleVersion;
        }

        public String getFormattedScore() {
            if (gradingResult == null || gradingResult.getUserScore() == null) {
                return "暂未评分";
            }
            return gradingResult.getUserScore().setScale(2, RoundingMode.HALF_UP) + "分";
        }
    }
